package CfengMiddleWare.model.mapper;

import CfengMiddleWare.model.entity.UserAccount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;

/**
 * <p>
 * 用户账户表 Mapper 接口
 * </p>
 *
 * @author cfeng
 * @since 2022-09-20
 */
public interface UserAccountMapper extends BaseMapper<UserAccount> {

    //根据userID查询账户
    UserAccount selectByUserId(@Param("userId") Integer userId);

    //不加锁方式更新账户余额
    int updateAmount(@Param("money") Double money, @Param("id") Integer id);

    //乐观锁方式更新账户余额
    int updateByPKVersion(@Param("money") Double money, @Param("id") Integer id,@Param("version") Integer version);

    //悲观锁方式查询，for update行锁
    UserAccount selectByUserIdLock(@Param("userId") Integer userId);

    //悲观锁范式更新，和普通方式相同，不需要额外处理
}
